package com.melichercik.code;

import java.io.Serializable;

public class Brick implements Serializable {
	
	public static final String START = "start";
	public static final String ROLL = "roll";
	public static final String STOP = "stop";
	public static final String COLOR = "color";
	public static final String LED = "led";
	public static final String DELAY = "delay";
	public static final String PRINT = "print";
	public static final String SOUND = "sound";
	public static final String VARIABLE = "var";
	public static final String LOOP = "loop";
	public static final String ENDLOOP = "endloop";
	public static final String WHILE = "while";
	public static final String ENDWHILE = "endwhile";
	public static final String IF = "if";
	public static final String THEN = "then";
	public static final String ENDTHEN = "endthen";
	public static final String ELSE = "else";
	public static final String ENDELSE = "endelse";
	public static final String ENDIF = "endif";
	public static final String RETURN = "return";
	public static final String END = "end";
	
	protected String type;
	public int x = 0;
	public int y = 0;
	protected int xx = 0;
	protected int yy = 0;
	protected int scale;
	
	public Brick(String type) {
		this.type = type;
	}
	
	public String getType() {
		return type;
	}
	
	public boolean click(int x,int y) {
		boolean result = false;
		
		if (x > this.xx && y > this.yy && x < (this.xx + this.scale) && y < (this.yy + this.scale)) {
			result = true;
		}
		
		return result;
	}
	
	protected String getCaption() {
		if (type == ENDTHEN || type == ENDELSE) {
			return "END"; 
		}
		return type.toUpperCase();
	}
	
	protected static String getCaption(String type) {
		return type.toUpperCase();
	}
	
	protected String textTruncate(String text) {
		String result = "";
		if (text.length() > 8) {
			result = text.substring(0, 6) + "...";
		} else {
			result = text;
		}
		
		return result;
	}
	
}
